package com.wy.projectssj.service.impl;

import com.wy.projectssj.dao.SysLogDao;
import com.wy.projectssj.domain.PageBean;
import com.wy.projectssj.domain.SysLog;
import com.wy.projectssj.service.SysLogService;
import com.wy.projectssj.utils.Uuid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: wy
 * @Date:2019/8/29 11:49
 */
 @Service
public class SysLogServiceImpl implements SysLogService {
     @Autowired
      private SysLogDao sysLogDao;
    @Override
    public PageBean<SysLog> findAll(Integer rows, Integer currentPage) {
          PageBean<SysLog> pb=new PageBean<>();
            Integer totalCount=sysLogDao.findAll();
             Integer totalPage=totalCount%rows==0?totalCount/rows:totalCount/rows+1;
             Integer start=(currentPage-1)*rows;
        List<SysLog> list = sysLogDao.findByCondition(start, rows);
               pb.setTotalPage(totalPage);
               pb.setTotalCount(totalCount);
               pb.setRows(rows);
               pb.setList(list);
               pb.setCurrentPage(currentPage);
        return pb;
    }

    @Override
    public int save(SysLog sysLog) {
        sysLog.setId(Uuid.getUuid());

        return sysLogDao.save(sysLog);
    }
}
